// index.js
const app=getApp();
Page({
  data:{
  },
  newRoom(){
    wx.navigateTo({
      url: '/pages/newRoom/newRoom',
    })
  },
  // 显示电话弹窗
  showPhone(e){
    var rid=e.currentTarget.dataset.room.roomName;
    var phone=e.currentTarget.dataset.room.phone;
    wx.showModal({
      title: rid+"的电话号码:"+phone,
    })
  },
  // 跳转到房间详情
  roomInfo(e){
    var rid=e.currentTarget.dataset.room.rid;//id is the id from roomdata,not the index
    wx.navigateTo({
      url: '/pages/roomInfo/roomInfo?rid='+rid,
    })
    
  },
/**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    
  },
  onShow(options){
      //get the roomlist
      wx.request({
        url: app.globalData.url,
        method:'GET',
        success:(res)=>{
          this.setData({
            roomList:res.data
          })
          if(this.data.roomList==0){
            wx.redirectTo({
              url: '/pages/empty/empty',
            })
          }
        }
      })
      //get the avatar
      var userAvatar=wx.getStorageSync('userAvatar')
      this.setData({
        userAvatar:userAvatar
      })
    },

  })
